package com.example.service.impl;

import com.example.mapper.DateMessageSumMapper;
import com.example.model.DateMessageSum;
import com.example.service.IDateMessageSumService;
import com.example.utils.DateUtils;
import com.example.utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import java.util.Date;
import java.util.List;

public class DateMessageSumServiceImpl implements IDateMessageSumService {

    public DateMessageSum getMySelfMessageSum(Date start,Date end,Long groupId,Long qq) {
        // 1、获取sqlSessionFactory对象
        SqlSessionFactory sqlSessionFactory = MyBatisUtils.getSqlSessionFactory();
        // 2、获取sqlSession对象
        SqlSession openSession = sqlSessionFactory.openSession();
        try {
            // 3、获取接口的实现类对象
            //会为接口自动的创建一个代理对象，代理对象去执行增删改查方法
            DateMessageSumMapper dateMessageMapper = openSession.getMapper(DateMessageSumMapper.class);
            return dateMessageMapper.getMySelfMessageSum(start, end , groupId, qq);
        } finally {
            openSession.close();
        }
    }

    public List<DateMessageSum> getDragonKing(Date start,Date end,Long groupId) {
        String order = "messageNum";//排序字段
        // 1、获取sqlSessionFactory对象
        SqlSessionFactory sqlSessionFactory = MyBatisUtils.getSqlSessionFactory();
        // 2、获取sqlSession对象
        SqlSession openSession = sqlSessionFactory.openSession();
        try {
            // 3、获取接口的实现类对象
            //会为接口自动的创建一个代理对象，代理对象去执行增删改查方法
            DateMessageSumMapper dateMessageMapper = openSession.getMapper(DateMessageSumMapper.class);
            return dateMessageMapper.getDragonKing(start,end,groupId,order);
        } finally {
            openSession.close();
        }
    }
}
